package vn.allmobile.ambnews.customview;

import vn.allmobile.ambnews.R;
import vn.allmobile.ambnews.utils.GlobalApplication;
import vn.allmobile.ambnews.utils.Log;
import android.app.Dialog;
import android.content.Context;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;

public class LoadingDialog {
	static LoadingDialog _loadingDialog;
	Dialog _dialog;
	
	static Context _context = GlobalApplication._();
	
	public LoadingDialog(Context context) {
	
		_dialog = new Dialog(context) ;	
		_dialog.requestWindowFeature(1);
		_dialog.setCancelable(false);	    
		LayoutInflater li = LayoutInflater.from(_context);
		View v = li.inflate(R.layout.customprocessdialog,null);
		/* bt.setOnClickListener(new View.OnClickListener() {		
			@Override
			public void onClick(View v) {
				Log.v("close diaglog");	
				_dialog.dismiss();
				mHandle.sendEmptyMessage(cancel);
			}
		});*/
	    _dialog.setContentView(v);				
	}
	
	
	public LoadingDialog(Context context,final Handler mHandle, final int cancel) {
		
		_dialog = new Dialog(context) ;	
		_dialog.requestWindowFeature(1);
		_dialog.setCancelable(false);	    
		LayoutInflater li = LayoutInflater.from(_context);
		View v = li.inflate(R.layout.customprocessdialog,null);
		ImageView bt = (ImageView)v.findViewById(R.id.closebtn);
	    bt.setOnClickListener(new View.OnClickListener() {		
			@Override
			public void onClick(View v) {
				Log.v("close diaglog");	
				_dialog.dismiss();
				mHandle.sendEmptyMessage(cancel);
			}
		});
	    _dialog.setContentView(v);				
	}	
		
	public  void show()
	{
		if (!_dialog.isShowing())
	    {
	      _dialog.show();
	      //Log.e("", "Show Dialog...");
	    }		
	}
	
	public  void hide()
	{
		if(_dialog.isShowing())
			_dialog.dismiss();
	}
}
